package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.SysGeneralWordCategory;
import com.ruoyi.system.service.ISysGeneralWordCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysGeneralWord;
import com.ruoyi.system.service.ISysGeneralWordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 普通词Controller
 * 
 * @author ruoyi
 * @date 2022-08-19
 */
@RestController
@RequestMapping("/system/generalWord")
public class SysGeneralWordController extends BaseController
{
    @Autowired
    private ISysGeneralWordService sysGeneralWordService;

    @Autowired
    private ISysGeneralWordCategoryService sysGeneralWordCategoryService;

    /**
     * 查询普通词列表
     */
    @PreAuthorize("@ss.hasPermi('system:generalWord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGeneralWord sysGeneralWord)
    {
        startPage();
        List<SysGeneralWord> list = sysGeneralWordService.selectSysGeneralWordList(sysGeneralWord);
        return getDataTable(list);
    }

    /**
     * 导出普通词列表
     */
    @PreAuthorize("@ss.hasPermi('system:generalWord:export')")
    @Log(title = "普通词", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysGeneralWord sysGeneralWord)
    {
        List<SysGeneralWord> list = sysGeneralWordService.selectSysGeneralWordList(sysGeneralWord);
        ExcelUtil<SysGeneralWord> util = new ExcelUtil<SysGeneralWord>(SysGeneralWord.class);
        return util.exportExcel(list, "普通词数据");
    }

    /**
     * 获取普通词详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:generalWord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysGeneralWordService.selectSysGeneralWordById(id));
    }

    /**
     * 新增普通词
     */
    @PreAuthorize("@ss.hasPermi('system:generalWord:add')")
    @Log(title = "普通词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGeneralWord sysGeneralWord)
    {
        return toAjax(sysGeneralWordService.insertSysGeneralWord(sysGeneralWord));
    }

    /**
     * 修改普通词
     */
    @PreAuthorize("@ss.hasPermi('system:generalWord:edit')")
    @Log(title = "普通词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGeneralWord sysGeneralWord)
    {
        return toAjax(sysGeneralWordService.updateSysGeneralWord(sysGeneralWord));
    }

    /**
     * 删除普通词
     */
    @PreAuthorize("@ss.hasPermi('system:generalWord:remove')")
    @Log(title = "普通词", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysGeneralWordService.deleteSysGeneralWordByIds(ids));
    }
}
